-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[URLSession]Fix for a timeout bug(SR-2681) #911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1293512
to
f04bfc1
Compare
With the current URLSession testing infrastructure, a test case for this, is a challenge. |
I have no comments on implementation, except for adding
|
Oh, now I see that i didn't understand the problem with tests correctly. |
Thanks @naithar I have added the guard |
@pushkarnk var bytes = Array(data.utf8)
for _ in 0..<5 {
sleep(1)
_ = try? attempt("write", valid: isNotNegative, CInt(write(connectionSocket, &bytes, bytes.count)))
} |
The diff looks reasonable but we should be able to get some kind of unit test in place for this. |
@naithar Thanks for your work. I will try out your suggestion. I was hoping that we can also delay the response as in:
I did this and I see a crash. Investigating it now. |
Does crash message anything? Maybe "Trying to access a behaviour for a task that in not in the registry."? I can sometimes reproduce this by just delaying response for long enough. This sometimes happens, because |
Not sure what happened, but reapplying a PR to current |
@naithar Yes, I did see that fatal error. Nevertheless, your patch looks good and the test runs well. I am wondering how we go about. I'd suggest we have this PR merged first and then you create a PR with your patch. |
I also realised that I need to cancel the timer when |
@pushkarnk i can also create a PR with test commented out. Actually i'm not agains you taking this test implementation into this PR. |
You creating the PR with calls to the new tests commented out is a better idea, in my opinion :) |
Then I'll do it now. |
Submitted #913 |
5b5bc08
to
d4e8ecd
Compare
That's strange. I'll look into it a little more. |
Yes, looks like we need to cancel the timeoutTimer in |
Actually Also moving |
Running Cancel test actually causes this error for
It's not displayed or handled because server is starting with this code (i guess the problem is in globalDispatchQueue.async {
do {
try self.runServer(with: serverReady)
} catch {
XCTAssertTrue(true)
return
}
} Also not signaling semaphore in @pushkarnk I see several workarounds:
|
Switching } catch let e as ServerError {
if e.operation != "bind" { continue } with } catch let e as ServerError {
if e.operation == "bind" { continue } in |
Thanks @naithar That seems like a fix (not a workaround). We retry on a bind failure and throw an error otherwise. |
runServer must retry on a bind failure - thanks to Sergey (@naithar)
@swift-ci please test |
@swift-ci please test and merge |
Currently, we use the
URLSessionConfiguration.timeoutIntervalForRequest
value to trigger a timeout. https://bugs.swift.org/browse/SR-2681 reported a bug in which the timeout counter is not reset on every data transfer.This is from the API doc:
This patch tries to reuse the
_TimeoutSource
class which is currently used to trigger timeouts in MultiHandle, with some modifications. We reset the timer every time data is available.